import { PaginationProps } from '@arco-design/web-react';

export function getPageInfo(
  data: {
    pageSize: number;
    page: number;
    pageCount: number;
    [key: string]: any;
  },
  pageInfo: {
    page?: number;
    pageSize?: number;
    showTotal?: boolean;
    totalField?: string;
    pageField?: string;
    pageSizeField?: string;
    sizeCanChange?: boolean
  } = {},
): PaginationProps {
  const {
    showTotal,
    totalField = 'recordsCount',
    pageField = 'page',
    pageSizeField = 'pageSize',
    sizeCanChange
  } = pageInfo;

  const pagination: PaginationProps = {
    pageSize: data?.[pageSizeField] || pageInfo?.[pageSizeField] || 10,
    sizeOptions: [10, 20, 100, 200],
    showTotal: false,
    current: data?.[pageField] || pageInfo?.[pageField] || 1,
    sizeCanChange: false
  };
  if (showTotal) {
    pagination.total = data?.[totalField];
    pagination.showTotal = true;
  }
  if (sizeCanChange) {
    pagination.sizeCanChange = true
  }
  return pagination;
}
